#ifndef KDNODE_H_
#define KDNODE_H_

class Triangle;

class KdNode
{
public:
	KdNode() :
		data( 6)
	{
	}
	;
	inline void setAxis(int a_Axis)
	{
		data = (data & 0xfffffffc) + a_Axis;
	}
	inline int getAxis() const
	{
		return data & 3;
	}
	inline void setSplitPos(float a_Pos)
	{
		split = a_Pos;
	}
	inline float getSplitPos() const
	{
		return split;
	}
	inline void setLeft(KdNode* a_Left)
	{
		data = (unsigned long)a_Left + (data & 7);
	}
	inline KdNode* getLeft() const
	{
		return (KdNode*)(data&0xfffffff8);
	}
	inline KdNode* getRight() const
	{
		return ((KdNode*)(data&0xfffffff8)) + 1;
	}
//	void Add(Primitive* a_Prim);
	
	inline bool isLeaf() const
	{
		return ((data & 4) != 0);
	}
	inline void setLeaf(bool a_Leaf)
	{
		data = (a_Leaf) ? (data|4) : (data&0xfffffffb);
	}
	inline Triangle** getTriangleList() const
	{
		return (Triangle**)(data&0xfffffff8);
	}
	inline void setTriangleList(Triangle** o)
	{
		data = (unsigned long)o + (data & 7);
	}

private:
	unsigned long data;
	float split;
};

#endif /*KDNODE_H_*/
